using UnityEngine;
using UnityEditor;
using SgsUI;

namespace SgsUI.Editor
{
    [CustomPropertyDrawer(typeof(Align),true)]

    public class AlignDataDrawer :PropertyDrawer
    {
        public override void OnGUI(Rect rect, SerializedProperty prop, GUIContent label) 
        {
            Rect drawRect = rect;
            drawRect.height = EditorGUIUtility.singleLineHeight;

            EditorGUI.BeginProperty(drawRect, label, prop);

            drawRect = EditorGUI.PrefixLabel(drawRect, label);

            SerializedProperty prop_anchor = prop.FindPropertyRelative("anchor");
            SerializedProperty prop_x = prop.FindPropertyRelative("x");
            SerializedProperty prop_y = prop.FindPropertyRelative("y");

            drawRect.width = drawRect.width/3.2f;
            EditorGUIUtility.labelWidth = drawRect.width/2.5f;

            EditorGUI.PropertyField(drawRect, prop_anchor);
            drawRect.x += drawRect.width*1.1f;
            
            EditorGUI.PropertyField(drawRect, prop_x);
            drawRect.x += drawRect.width*1.1f;

            EditorGUI.PropertyField(drawRect, prop_y);
            drawRect.x += drawRect.width*1.1f;

            EditorGUI.EndProperty();
        }

        public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
        {
            return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
        }
    }
}